<?php

function list_diklat(){
	
	$header = array(
		'Tanggal'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Kategori Pelatihan'=>array('style'=>'border-bottom:2px solid;width:25%'),  
		'Nama Pelatihan'=>array('style'=>'border-bottom:2px solid;width:25%'),  
		'NIK'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Nama Karyawan'=>array('style'=>'border-bottom:2px solid;width:25%'),  
		'Hasil'=>array('style'=>'border-bottom:2px solid;width:5%'),  
	);
	
	$query = "SELECT * FROM karyawan_pelatihan a
		INNER JOIN jadwal_pelatihan b
			ON a.jadwal_pelatihan_id = b.jadwal_pelatihan_id
		INNER JOIN kategori_pelatihan c
			ON c.kategori_pelatihan_id = b.kategori_pelatihan_id
		INNER JOIN materi_pelatihan d 
			ON d.materi_pelatihan_id=b.materi_pelatihan_id 
		ORDER BY b.tanggal_mulai DESC 	
	 ";
	 
	$result = my_query($query);
	$row = array();
	$materi_sama=false;	
	while($ey = my_fetch_array($result) ){
		$karyawan = loaddata_karyawan($ey['karyawan_id']); 
		if(empty($karyawan['gelar'])){
			$nama_karyawan=ucfirst($karyawan['nama']) ;
		}else{
			$nama_karyawan=trim(ucfirst($karyawan['nama'])).", ".$karyawan['gelar'] ;
		}
		if($materi_sama){
			$row[] = array(
				'tgl'=>' ',
				'kategori'=>' ',
				'materi'=> ' ',
				'nik'=> $karyawan['nik']  ,   
				'nama'=>  $nama_karyawan ,   
				'hasil'=> $ey['hasil']  ,   
			);
		}else{	
			$row[] = array(
				'tgl'=>DATE('d-m-Y', strtotime($ey['tanggal_mulai'])), 
				'kategori'=>$ey['kategori_pelatihan_label'], 
				'materi'=>  $ey['materi_pelatihan_label'] ,
				'nik'=> $karyawan['nik']  ,   
				'nama'=>  $nama_karyawan ,   
				'hasil'=> $ey['hasil']  ,   
			);
//			$materi_sama=true;
		}

		
	}	
	$datas = table_rows($row);
	$menuontop = array(
		'Cetak' => array('onclick'=>'javascript:window.open(\'index.php?com=report&task=rpt_diklat\',\'mywin\',\'left=20,top=20,width=800,height=600,toolbar=0,resizable=0\');')
	);
	$printmenu = additional_menu_on_list( $menuontop ,'');
	return $printmenu.table_builder($header , $datas ,  5 , false );
}
